#include "sock_define.h"
/* 
 * description: use for login
 *
 * */
extern int User_login(int login_fd);
extern void sig_chld(int signo);

int main(int argc, char **argv)
{
	int listenfd, connfd;
	pid_t childpid;
	socklen_t clilen;
	struct sockaddr_in cliaddr, servaddr;
	listenfd = socket(AF_INET, SOCK_STREAM, 0);
	
	bzero(&servaddr, sizeof(servaddr));
	char buff[MAX_LINE];memset(buff, 0, sizeof(buff));
	
	servaddr.sin_family = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port = htons(LOGIN_PORT);
	
	bind(listenfd, (SA *) &servaddr, sizeof(servaddr));
	listen(listenfd, LISTENQ);
	signal(SIGCHLD, sig_chld);
	
	for(;;)
	{
		clilen = sizeof(cliaddr);
		connfd = accept(listenfd, (SA *) &cliaddr, &clilen);
		printf("connection from IP: %s Port: %d\n", inet_ntop(AF_INET, &cliaddr.sin_addr, buff, sizeof(buff)), ntohs(cliaddr.sin_port));
		if((childpid = fork()) == 0)
		{
			close(listenfd);/* close the listening socket*/
			
			User_login(connfd);/* login */

			exit(0);
		}
		close(connfd);
		

	}

}



